package net.coldsky.common.util;

import java.util.Random;

import org.springframework.util.Assert;

public abstract class RandomUtils {
	/**
	 * 用java.util.UUID获得的随机的long
	 */
	public static long randomLong(){
		return java.util.UUID.randomUUID().getMostSignificantBits();
	}
	
	/**
	 * 根据位数随机生成int格式
	 * @param 生成数字格式字符串的位数
	 */
	public static String randomString4Int(int digit){
		Assert.isTrue(digit>0);
		Random random = new Random();
		StringBuilder re = new StringBuilder(digit);
		
		for(int i=0;i<digit;i++){
			//i 0-9
			re.append(random.nextInt(10));
		}
		
		return re.toString();
	}
	
	public static String randomString4Letter(int digit){
		Assert.isTrue(digit>0);
		Random random = new Random();
		StringBuilder re = new StringBuilder(digit);
		
		boolean isBig;
		for(int i=0;i<digit;i++){
			//A-Z 65-90
			//a-z 97-122
			isBig = (random.nextInt(2)==1);
			if(isBig){
				re.append((char)(random.nextInt(26)+65));
			}else{
				re.append((char)(random.nextInt(26)+97));
			}
		}
		return re.toString();
	}
	
	public static void main(String[] args) {
		System.out.println(randomString4Int(1024));
		System.out.println(randomString4Letter(1024));
	}
}
